#ifndef ALSARENDERER_H_
#define ALSARENDERER_H_

#include "audiorenderer.h"
#include <alsa/asoundlib.h>
#include <string>
#include <queue>

class AlsaFrame;

class AlsaRenderer : public AudioRenderer
{
public:
	AlsaRenderer();
	~AlsaRenderer();
	
	void setFormat(const AudioFormat& format);
	
	void play();
	void pause();
	void stop();
	void adjustVolume(float offset);
	
	bool hasBufferSpace();
	void flushBuffers();
	void queueFrame(const AudioFrame& frame);
	
	double getCurrentPts();
	void playFrameData();
	
private:
	void throwOnError(int err, const std::string& message);
	void clearBuffers();
	
	snd_pcm_t* 				m_pAudioDevice;
	snd_pcm_uframes_t  		m_BufferSize;
	snd_pcm_uframes_t 		m_PeriodSize;
	snd_async_handler_t*	m_pAlsaCallBack;
	
	long					m_FramesPerPacket;
	int						m_FrameSize;
	double					m_LastPts;
	
	std::queue<AlsaFrame*> 	m_Frames;
};

#endif
